package com.tuantuan.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.tuantuan.dao.CommenDao;
import com.tuantuan.model.Teachers;
import com.tuantuan.service.CommenService;
/**
 * 教师信息控制层
 * @author Administrator
 *
 */
@Controller
public class TeacherController {

	@Resource(name="TeacherDao")
	private CommenDao<Teachers> teach;
	
	@Resource(name="TeacherService")
	private CommenService<Teachers> teachSer;
	
	public String toQueryTeachers(HttpServletRequest request,Teachers t){
		
		return "";
	}
	/**
	 * 分页查询教师资料
	 * @param request
	 * @param response
	 * @param tch
	 * @return
	 */
	@RequestMapping("/teacher/queryTeachers.do")
	@ResponseBody
	public Map<String, Object> queryByPage(HttpServletRequest request,HttpServletResponse response,Teachers tch){
		Map<String, Object> map = new HashMap<String, Object>();
		Teachers t = teach.queryByPage(tch);
		map.put("page", t);
		return map;
	}
	/**
	 * 添加教师资料
	 * @param request
	 * @param t
	 * @return
	 */
	@RequestMapping("/teacher/addTeachers.do")
	@ResponseBody
	public String addTeacher(HttpServletRequest request,Teachers t){
		
		return teachSer.addEntity(t);
	}
	/**
	 * 获取更新教师信息页面数据
	 * @param request
	 * @param tcId
	 * @return
	 */
	@RequestMapping("/teacher/toUpdateTeachers.do")
	public String toUpdateTeachers(HttpServletRequest request, int tcId){
		Teachers t = new Teachers();
		t.setTcId(tcId);
		Teachers tt = teach.queryById(t);
		request.setAttribute("teachers", tt);
		return "teacher/teacherView";
		
		
	}
	@RequestMapping("/teacher/updateTeachers.do")
	@ResponseBody
	public String  updateStudent(HttpServletRequest request,HttpServletResponse response,Teachers t){
		return teachSer.updateEntity(t);
	}
	/**
	 * 教师资料删除
	 * @param request
	 * @param tcId
	 * @param pageCounts
	 * @return
	 */
	@RequestMapping("/teacher/deleteTeacher.do")
	public String deleteTeacher(HttpServletRequest request,int tcId,int pageCounts){
		String flag = teachSer.deleteEntity(tcId);
		request.setAttribute("flag", flag);
		request.setAttribute("pageCounts", pageCounts);
		return "teacher/teacher";
		
	}
	public CommenDao<Teachers> getTeach() {
		return teach;
	}
	public void setTeach(CommenDao<Teachers> teach) {
		this.teach = teach;
	}
	public CommenService<Teachers> getTeachSer() {
		return teachSer;
	}
	public void setTeachSer(CommenService<Teachers> teachSer) {
		this.teachSer = teachSer;
	}
	
	
}
